The following section provides an example of how to create a track matte.
Listing 15 provides an example of how to create a track matte. The CreateTrackMatte function adds an uninitialized, 8-bit-deep, grayscale matte to a track. The UpdateTrackMatte function draws a gray ramp rectangle around the edge of the matte and fills the center of the matte with black. (A ramp rectangle shades gradually from light to dark in smooth increments.)
Listing 15 Creating a track matte
void CreateTrackMatte (Track theTrack)
{
QDErr err;
GWorldPtr aGW;
Rect trackBox;
Fixed trackHeight;
Fixed trackWidth;
CTabHandle grayCTab;
GetTrackDimensions (theTrack, &trackWidth, &trackHeight);
SetRect (&trackBox, 0, 0, FixRound (trackWidth),
FixRound (trackHeight));
grayCTab = GetCTable(40); /* 8 bit + 32 = 8 bit gray */
err = NewGWorld (&aGW, 8, &trackBox, grayCTab,
(GDHandle) nil, 0);
DisposeCTable (grayCTab);
if (!err && (aGW != nil))
{
SetTrackMatte (theTrack, aGW->portPixMap);
DisposeGWorld (aGW);
}
}
void UpdateTrackMatte (Track theTrack)
{
OSErr err;
PixMapHandle trackMatte;
PixMapHandle savePortPix;
Movie theMovie;
GWorldPtr tempGW;
CGrafPtr savePort;
GDHandle saveGDevice;
Rect matteBox;
short i;
theMovie = GetTrackMovie (theTrack);
trackMatte = GetTrackMatte (theTrack);
if (trackMatte == nil)
{
/* track doesn't have a matte, so give it one */
CreateTrackMatte (theTrack);
trackMatte = GetTrackMatte (theTrack);
if (trackMatte == nil)
return;
}
GetGWorld (&savePort, &saveGDevice);
matteBox = (**trackMatte).bounds;
err = NewGWorld(&tempGW,
(**trackMatte).pixelSize, &matteBox,
(**trackMatte).pmTable, (GDHandle) nil, 0);
if (err || (tempGW == nil)) return;
SetGWorld (tempGW, nil);
savePortPix = tempGW->portPixMap;
LockPixels (trackMatte);
SetPortPix (trackMatte);
/* draw a gray ramp rectangle around the edge of the matte */
for (i = 0; i < 35; i++)
{
RGBColor aColor;
long tempLong;
tempLong = 65536 - ((65536 / 35) * (long)i);
aColor.red = aColor.green = aColor.blue = tempLong;
RGBForeColor(&aColor);
FrameRect (&matteBox);
InsetRect (&matteBox, 1, 1);
}
/* fill the center of the matte with black */
ForeColor (blackColor);
PaintRect (&matteBox);
SetPortPix (savePortPix);
SetGWorld (savePort, saveGDevice);
DisposeGWorld (tempGW);
UnlockPixels (trackMatte);
SetTrackMatte (theTrack, trackMatte);
DisposeMatte (trackMatte);
}